#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QSharedPointer>

#include "dockwidgethelper.h"
#include "framelessmainwindow/framelessmainwindowimpl.h"

class QSystemTrayIcon;
namespace stitch
{
    class ViewArea;
    class Event;
    enum
    {
        RESTART_EXIT_CODE = 1000
    };
    class MainWindow : public FramelessMainWindowImpl
    {
        Q_OBJECT
    public:
        friend class DockWidgetHelper;
        explicit MainWindow(QWidget *p_parent = nullptr);
        ~MainWindow();
        MainWindow(const MainWindow &) = delete;
        void operator=(const MainWindow &) = delete;

        void kickOffOnStart(const QStringList &p_paths);
        void quitApp();
        void showMainWindow();
        void openFiles(const QStringList &p_files);
        void setStayOnTop(bool p_enabled);
    signals:
        void mainWindowStarted();

        // @m_response of @p_event: true to continue the close, false to stop the close.
        void mainWindowClosed(const QSharedPointer<Event> &p_event);

        // No user interaction is available.
        void mainWindowClosedOnQuit();

        void layoutChanged();
    private slots:
        void closeOnQuit();
        void showTips(const QString &p_message, int p_timeoutMilliseconds);
    private:
        Qt::WindowStates m_windowOldState = Qt::WindowMinimized;

        void setupUI();
        void setupShortcuts();
        void setupCentralWidget();
        void setupDocks();
        void setupToolBar();
        void setupStatusBar();
        void setupTipsArea();
        void setupSystemTray();

        void setupOutlineViewer();
        void setupConsoleViewer();
        void setupSearchPanel();
        void setupLocationList();
        void setupSnippetPanel();
        void setupHistoryPanel();
        void setupNotebookExplorer();
        void setupTagExplorer();

        void createTipsArea();
        void setTipsAreaVisible(bool p_visible);


        DockWidgetHelper m_dockWidgetHelper;
        ViewArea *m_viewArea = nullptr;
        QLabel *m_tipsLabel = nullptr;
        QTimer *m_tipsTimer = nullptr;
        QSystemTrayIcon *m_trayIcon = nullptr;
        // -1: do not request to quit;
        // 0 and above: exit code.
        int m_requestQuit = -1;
    };
}

#endif // MAINWINDOW_H
